<template>
  <div>
    <!--  进行某动作时，增加自身属性-->
    <div>
      <Button @click="reset">重置</Button>
      <Button @click="getStr">生成</Button>
      <Radio v-model="type" true-value="hit">攻击时</Radio>
      <Radio v-model="type" true-value="cast">释放时</Radio>
      <Radio v-model="type" true-value="hp0">进入副本无条件触发</Radio>
      <Radio v-model="type" true-value="HP">生命值达到一定程度</Radio>
      <Radio v-model="type" true-value="MP">法力值达到一定程度</Radio>
      冷却时间：<Input v-model="coolTime" /> 概率：<Input v-model="prop" /> 持续时间：<Input v-model="duration" />
      <p>增加属性</p>
      力量<Input v-model="num.phAtk.num" /> 智力<Input v-model="num.mgAtk.num" /> 体力<Input v-model="num.phDef.num" /> 精力<Input v-model="num.mgDef.num" /> 物理攻击力<Input v-model="num.phAtkEQ.num" /> 魔法攻击力<Input v-model="num.mgAtkEQ.num" /> 独立攻击力<Input v-model="num.seAtk.num" /> 攻击速度<Input v-model="num.atkSP.num" /> 释放速度<Input v-model="num.castSP.num" /> 移动速度<Input v-model="num.moveSP.num" /> 火属性强化<Input v-model="num.fireE.num" /> 光属性强化<Input v-model="num.lightE.num" /> 冰属性强化<Input v-model="num.waterE.num" /> 暗属性强化<Input v-model="num.darkE.num" /> 全属性强化<Input v-model="num.allE.num" />
      <p>伤害类型词条</p>
      <Radio v-model="damageType" true-value="increase">增加伤害</Radio>
      <Radio v-model="damageType" true-value="crit">暴击伤害</Radio>
      <Radio v-model="damageType" true-value="skill">技能攻击力</Radio>
      <Radio v-model="damageType" true-value="add">附加伤害</Radio>
      <Radio v-model="damageType" true-value="rate">最终伤害</Radio>
      <Input v-model="damageRate" />
      <!--    生成文本-->
      <textarea v-model="result" name="" id="" cols="30" rows="10"></textarea>
    </div>
  </div>
</template>

<script>
export default {
  name: 'reduce',
  data() {
    return {
      type: 'hit',
      prop: 0,
      coolTime: 0,
      duration: 0,
      damageType: 'increase',
      num: {
        phAtk: {
          stat: 'physical attack',
          num: 0
        },
        mgAtk: {
          stat: 'magical attack',
          num: 0
        },
        phDef: {
          stat: 'physical defence',
          num: 0
        },
        mgDef: {
          stat: 'physical defence',
          num: 0
        },
        phAtkEQ: {
          stat: 'equipment physical attack',
          num: 0
        },
        mgAtkEQ: {
          stat: 'equipment magical attack',
          num: 0
        },
        seAtk: {
          stat: 'separate attack',
          num: 0
        },
        atkSP: {
          stat: 'attack speed',
          num: 0
        },
        castSP: {
          stat: 'cast speed',
          num: 0
        },
        moveSP: {
          stat: 'move speed',
          num: 0
        },
        fireE: {
          stat: 'fire attack',
          num: 0
        },
        lightE: {
          stat: 'light attack',
          num: 0
        },
        waterE: {
          stat: 'water attack',
          num: 0
        },
        darkE: {
          stat: 'dark attack',
          num: 0
        },
        allE: {
          stat: 'all elemental attack',
          num: 0
        }
      },
      damageRate: 0,
      result: ''
    }
  },
  methods: {
    reset() {
      this.num = {
        phAtk: {
          stat: 'physical attack',
          num: 0
        },
        mgAtk: {
          stat: 'magical attack',
          num: 0
        },
        phDef: {
          stat: 'physical defence',
          num: 0
        },
        mgDef: {
          stat: 'physical defence',
          num: 0
        },
        phAtkEQ: {
          stat: 'equipment physical attack',
          num: 0
        },
        mgAtkEQ: {
          stat: 'equipment magical attack',
          num: 0
        },
        seAtk: {
          stat: 'separate attack',
          num: 0
        },
        atkSP: {
          stat: 'attack speed',
          num: 0
        },
        castSP: {
          stat: 'cast speed',
          num: 0
        },
        moveSP: {
          stat: 'move speed',
          num: 0
        },
        fireE: {
          stat: 'fire attack',
          num: 0
        },
        lightE: {
          stat: 'light attack',
          num: 0
        },
        waterE: {
          stat: 'water attack',
          num: 0
        },
        darkE: {
          stat: 'dark attack',
          num: 0
        },
        allE: {
          stat: 'all elemental attack',
          num: 0
        }
      }
    },
    getStr() {
      this.typeRender()
      this.statRender()
      this.rateRender()
    },
    typeRender() {
      if (this.type === 'hit') {
        this.result = '[if]\n' + '\t[hit]\n' + '\t\t1\n' + '\t[cooltime]\n' + '\t\t' + this.coolTime + '\n' + '[/if]'
      } else if (this.type === 'cast') {
        this.result = '[if]\n' + '\t[casting]\n' + '\t\t1\n' + '\t[cooltime]\n' + '\t\t' + this.coolTime + '\n' + '[/if]'
      } else if (this.type === 'hp0') {
        this.result = '[if]\n' + '\t[change status]\n' + '\t\t`hp`\n' + '\t\t`>`\n' + '\t\t`%`\t0\n' + '\t\t`end`\n' + '\t[cooltime]\n' + '\t\t' + this.coolTime + '\n' + '[/if]'
      }
    },
    statRender() {
      this.result = this.result+'\n[then]'
      for (let i in this.num) {
        console.log(i)
        if (this.num[i].num !== 0) {
          this.result = this.result + '\n\t[stat]\n' + '\t\t`' + this.num[i].stat + '`\n\t\t`%`' + '\t' + this.num[i].num
        }
      }
    },
    rateRender() {
      if (this.damageRate !== 0) {
        if (this.damageType === 'increase') {
          this.result = this.result + '\n[skill data up]\n' + '\t`[all]`\t174\t`[all]`\t`[static]`\t1\t`+`\t' + this.damageRate + '\t\n' + '[/skill data up]'
        } else if (this.damageType === 'crit') {
          this.result = this.result + '\n[skill data up]\n' + '\t`[all]`\t174\t`[all]`\t`[static]`\t2\t`+`\t' + this.damageRate + '\t\n' + '[/skill data up]'
        } else if (this.damageType === 'skill') {
          this.result = this.result + '\n[skill data up]\n' + '\t`[all]`\t174\t`[all]`\t`[static]`\t3\t`+`\t' + this.damageRate + '\t\n' + '[/skill data up]'
        } else if(this.damageType === 'add'){
          this.result = this.result + '\n[skill data up]\n' +
              '\t`[all]`\t174\t`[all]`\t`[static]`\t4\t`+`\t'+this.damageRate+'\t\n' +
              '[/skill data up]'
        } else if(this.damageType === 'rate'){
          this.result = this.result + '\n[skill data up]\n' +
              '\t`[all]`\t174\t`[all]`\t`[static]`\t5\t`+`\t'+this.damageRate+'\t\n' +
              '[/skill data up]'
        }
      }
      this.result = this.result+'\n[/then]'
    }
  }
}
</script>

<style scoped></style>
